//
//  SendTextView.m
//  XiangMuB
//
//  Created by lanou3g on 16/8/12.
//  Copyright © 2016年 lanou3g. All rights reserved.
//

#import "SendTextView.h"

#import "UIView+FrameView.h"

@interface SendTextView ()

@property (nonatomic, strong) UILabel *placeholderLabel;

@end

@implementation SendTextView


- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
       
        self.alwaysBounceVertical = YES;
        self.font = [UIFont systemFontOfSize:15];
        self.placeholderColor = [UIColor grayColor];
        
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChange) name:UITextViewTextDidChangeNotification object:nil];
        
    }
    return self;
    
}

#pragma mark method

- (void)textDidChange{
    
    self.placeholderLabel.hidden = self.hasText;
}

#pragma mark getter method

- (UILabel *)placeholderLabel{
    
    if (_placeholderLabel == nil) {
        
        _placeholderLabel = [[UILabel alloc] init];
        _placeholderLabel.numberOfLines = 0;
        _placeholderLabel.x = 4;
        _placeholderLabel.y = 7;
        [self addSubview:_placeholderLabel];
        
        
    }
    
    return _placeholderLabel;
    
}


#pragma mark setter method

- (void)setPlaceholderColor:(UIColor *)placeholderColor{
    
    _placeholderColor = placeholderColor;
    self.placeholderLabel.textColor = placeholderColor;
    
}


- (void)setPlaceholder:(NSString *)placeholder{
    
    _placeholder = placeholder;
    self.placeholderLabel.text = placeholder;
    
    [self setNeedsLayout];
}




- (void)layoutSubviews{
    
    [super layoutSubviews];
    self.placeholderLabel.width = self.width - self.placeholderLabel.x * 2;
    [self.placeholderLabel sizeToFit];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
